var ScottsJewels = ScottsJewels || {};

ScottsJewels.MockDatasource = (function () {

	var mockData = [ 
		{ text : "Barney Gumble", value : 1 },   	
		{ text : "Bart Simpson", value : 2 },	

		{ text : "Chief Clancy Wiggum", value : 3 },  
		{ text : "Cletus Spuckler", value : 4 },   		
		{ text : "Comic Book Guy", value : 5 },
		{ text : "Dr. Marvin Monroe", value : 6 },                

		{ text : "Dr. Nick Riveria", value : 7 },      		
		{ text : "Duffman", value : 8 },   
		{ text : "Fat Tony", value : 9 },	
		{ text : "Grandpa Simpson", value : 10 },    		

		{ text : "Groundskeeper Willie", value : 11 },   								
		{ text : "Homer Simpson", value : 12 },
		{ text : "Kent Brockman", value : 13 },                            		
        { text : "Krusty the Clown", value : 14 },        

		{ text : "Lisa Simpson", value : 15 },
		{ text : "Maggie Simpson", value : 16 },		
		{ text : "Marge Simpson", value : 17 },
		{ text : "Milhouse Van Houten", value : 18 },           		

		{ text : "Moe Szyslak", value : 19 },    
		{ text : "Ned Flanders", value : 20 },                  		
		{ text : "Otto Mann", value : 21 },                        		
        { text : "Patty Bouvier", value : 22 },                                    

		{ text : "Principal Seymour Skinner", value : 23 },             
		{ text : "Radioactive Man", value : 24 },        
		{ text : "Ralph Wiggum", value : 25 },            		
		{ text : "Reverend Timothy Lovejoy", value : 26 },            		

		{ text : "Rod Flanders", value : 27 },                    		
		{ text : "Selma Bouvier", value : 28 },                                		
		{ text : "Sideshow Mel", value : 29 },                

		{ text : "Sideshow Bob", value : 30 },                    
		{ text : "Todd Flanders", value : 31 },                        
		{ text : "Waylon Smithers", value : 32 }
	]

	return {

		search : function ( search ) {
		
			var result = [],
				total = mockData.length,
				regex = RegExp(search,"i"); // Case-insensitive
																								
			while ( total-- ) {

				if ( mockData[total].text.match(regex) ) {
					result.push( { text : mockData[total].text, value : mockData[total].value } );
				}			
			}
			
			result = result.reverse();   // Put the list back in alphabetical order ( the while loop reversed it ).

			
			return result;					
		},
		
		paginatedSearch : function ( search, pageSize, pageIndex ) {
		
            var result 	= ScottsJewels.MockDatasource.search ( search ),
				total 	= result.length;
		      
            result = result.slice(); // Clone the array.
		      		
            result = result.splice(pageIndex*pageSize,pageSize); // get the portion of the result set that corresponds to the pagination.
		
            return {data 	: result,
					total 	: total };		      		
		}
	}



})();